﻿/*
 * This software is the confidential and proprietary
 * information of NetBay
 * Such confidential information should not be disclosed
 * NetBay copyright(c) 2010
 */

#region using
using System.Data.Common;
using System.Data.OracleClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using NetBay.Core.DataAccess;
using System.ComponentModel;
using NetBay.Core.Extensions;
using System.Data;
using System.Data.SqlClient;
using Rio.Framework.RioManager;

#endregion

namespace Rio.Doc.DataAccess
{
    public class DA_Ocr
    {

        #region Enum
        /// <summary>
        /// List of DB functions to access data
        /// </summary>
        public enum DbFunction
        {
            [DescriptionAttribute("")]
            None,
            [DescriptionAttribute("P_OCR_MASK_Add")]
            AddMask,
            [DescriptionAttribute("P_OCR_MASK_Delete")]
            DeleteMask,
            [DescriptionAttribute("P_OCR_MASK_Update")]
            UpdateMask,
            [DescriptionAttribute("P_OCR_MASK_Get_ByFolderTypeId")]
            GetMaskByFolerTypeId,
            [DescriptionAttribute("P_OCR_REGION_Add")]
            AddRegion,
            [DescriptionAttribute("P_OCR_REGION_Delete")]
            DeleteRegion,
            [DescriptionAttribute("P_OCR_REGION_Get_ByMaskId")]
            GetRegionByMaskId,
            [DescriptionAttribute("P_OCR_MASK_Get_ById")]
            GetMaskById,
            [DescriptionAttribute("P_OCR_REGION_Update")]
            UpdateRegion
        }
        #endregion

        /// <summary>
        /// Adds the mask.
        /// </summary>
        /// <param name="p_sMaskLibelle">p_sMaskLibelle</param>
        /// <param name="p_lFolderTypeId">p_lFolderTypeId</param>
        /// <param name="p_sAuthorAreaName">p_sAuthorAreaName</param>
        /// <param name="p_lAuthorAreaTopLeftXCoord">p_lAuthorAreaTopLeftXCoord</param>
        /// <param name="p_lAuthorAreaTopLeftYCoord">p_lAuthorAreaTopLeftYCoord</param>
        /// <param name="p_lAuthorAreaHeight">p_lAuthorAreaHeight</param>
        /// <param name="p_lAuthorAreaWidth">p_lAuthorAreaWidth</param>
        /// <param name="p_lAuthorOcrType">p_lAuthorOcrType</param>
        /// <param name="p_sChronoNumberAreaName">p_sChronoNumberAreaName</param>
        /// <param name="p_lChronoNumberAreaTopLeftXCoord">p_lChronoNumberAreaTopLeftXCoord</param>
        /// <param name="p_lChronoNumberAreaTopLeftYCoord">p_lChronoNumberAreaTopLeftYCoord</param>
        /// <param name="p_lChronoNumberAreaHeight">p_lChronoNumberAreaHeight</param>
        /// <param name="p_lChronoNumberAreaWidth">p_lChronoNumberAreaWidth</param>
        /// <param name="p_lChronoNumberOcrType">p_lChronoNumberOcrType</param>
        /// <returns>Identifier of new mask.</returns>
        public static IDataReader AddMask(string p_sMaskLibelle, long p_lFolderTypeId, string p_sAuthorAreaName, long p_lAuthorAreaTopLeftXCoord,
            long p_lAuthorAreaTopLeftYCoord, long p_lAuthorAreaHeight, long p_lAuthorAreaWidth, long p_lAuthorOcrType, string p_sChronoNumberAreaName,
            long p_lChronoNumberAreaTopLeftXCoord, long p_lChronoNumberAreaTopLeftYCoord, long p_lChronoNumberAreaHeight, long p_lChronoNumberAreaWidth,
            long p_lChronoNumberOcrType)
        {
            var db = DbHelper.DataBase;

            var dbCommand = db.GetNewCommand(DbFunction.AddMask.szGetDescription());


            //Mask General Informations
            db.AddInParameter(dbCommand, "p_sMaskLibelle", DbType.String, p_sMaskLibelle);
            db.AddInParameter(dbCommand, "p_lFolderTypeId", DbType.Int32, p_lFolderTypeId);

            //Author Informations
            db.AddInParameter(dbCommand, "p_sOCR_MASK_DOC_AUT_ZONE_NAME", DbType.String, p_sAuthorAreaName);
            db.AddInParameter(dbCommand, "p_lOCR_MASK_DOC_AUT_X", DbType.Int32, p_lAuthorAreaTopLeftXCoord);
            db.AddInParameter(dbCommand, "p_lOCR_MASK_DOC_AUT_Y", DbType.Int32, p_lAuthorAreaTopLeftYCoord);
            db.AddInParameter(dbCommand, "p_lOCR_MASK_DOC_AUT_WIDTH", DbType.Int32, p_lAuthorAreaHeight);
            db.AddInParameter(dbCommand, "p_lOCR_MASK_DOC_AUT_HEIGHT", DbType.Int32, p_lAuthorAreaWidth);
            db.AddInParameter(dbCommand, "p_iOCR_MASK_DOC_AUT_TYPE_ID", DbType.Int32, p_lAuthorOcrType);

            //Chrono Number Informations
            db.AddInParameter(dbCommand, "p_sOCR_MASK_DOC_CHR_ZONE_NAME", DbType.String, p_sChronoNumberAreaName);
            db.AddInParameter(dbCommand, "p_lOCR_MASK_DOC_CHR_X", DbType.Int32, p_lChronoNumberAreaTopLeftXCoord);
            db.AddInParameter(dbCommand, "p_lOCR_MASK_DOC_CHR_Y", DbType.Int32, p_lChronoNumberAreaTopLeftYCoord);
            db.AddInParameter(dbCommand, "p_lOCR_MASK_DOC_CHR_WIDTH", DbType.Int32, p_lChronoNumberAreaHeight);
            db.AddInParameter(dbCommand, "p_lOCR_MASK_DOC_CHR_HEIGHT", DbType.Int32, p_lChronoNumberAreaWidth);
            db.AddInParameter(dbCommand, "p_iOCR_MASK_DOC_CHR_TYPE_ID", DbType.Int32, p_lChronoNumberOcrType);

            return db.ExecuteReader(dbCommand);
        }

        /// <summary>
        /// Updates the mask.
        /// </summary>
        /// <param name="p_lOcrMaskId">p_lOcrMaskId</param>
        /// <param name="p_sMaskLibelle">p_sMaskLibelle</param>
        /// <param name="p_lFolderTypeId">p_lFolderTypeId</param>
        /// <param name="p_sAuthorAreaName">p_sAuthorAreaName</param>
        /// <param name="p_lAuthorAreaTopLeftXCoord">p_lAuthorAreaTopLeftXCoord</param>
        /// <param name="p_lAuthorAreaTopLeftYCoord">p_lAuthorAreaTopLeftYCoord</param>
        /// <param name="p_lAuthorAreaHeight">p_lAuthorAreaHeight</param>
        /// <param name="p_lAuthorAreaWidth">p_lAuthorAreaWidth</param>
        /// <param name="p_lAuthorOcrType">p_lAuthorOcrType</param>
        /// <param name="p_sChronoNumberAreaName">p_sChronoNumberAreaName</param>
        /// <param name="p_lChronoNumberAreaTopLeftXCoord">p_lChronoNumberAreaTopLeftXCoord</param>
        /// <param name="p_lChronoNumberAreaTopLeftYCoord">p_lChronoNumberAreaTopLeftYCoord</param>
        /// <param name="p_lChronoNumberAreaHeight">p_lChronoNumberAreaHeight</param>
        /// <param name="p_lChronoNumberAreaWidth">p_lChronoNumberAreaWidth</param>
        /// <param name="p_lChronoNumberOcrType">p_lChronoNumberOcrType</param>
        /// <returns></returns>
        public static void UpdateMask(long p_lOcrMaskId, string p_sOcrMaskLibelle, string p_sAuthorAreaName, long p_lAuthorAreaTopLeftXCoord,
            long p_lAuthorAreaTopLeftYCoord, long p_lAuthorAreaHeight, long p_lAuthorAreaWidth, long p_lAuthorOcrType, string p_sChronoNumberAreaName,
            long p_lChronoNumberAreaTopLeftXCoord, long p_lChronoNumberAreaTopLeftYCoord, long p_lChronoNumberAreaHeight, long p_lChronoNumberAreaWidth,
            long p_lChronoNumberOcrType)
        {
            var db = DbHelper.DataBase;
            var dbCommand = db.GetNewCommand(DbFunction.UpdateMask.szGetDescription(), false);

            //General Informations
            db.AddInParameter(dbCommand, "p_lOcrMaskId", DbType.Int32, p_lOcrMaskId);
            db.AddInParameter(dbCommand, "p_sOcrMaskLibelle", DbType.String, p_sOcrMaskLibelle);

            //Author Informations
            db.AddInParameter(dbCommand, "p_sOCR_MASK_DOC_AUT_ZONE_NAME", DbType.String, p_sAuthorAreaName);
            db.AddInParameter(dbCommand, "p_lOCR_MASK_DOC_AUT_X", DbType.Int32, p_lAuthorAreaTopLeftXCoord);
            db.AddInParameter(dbCommand, "p_lOCR_MASK_DOC_AUT_Y", DbType.Int32, p_lAuthorAreaTopLeftYCoord);
            db.AddInParameter(dbCommand, "p_lOCR_MASK_DOC_AUT_WIDTH", DbType.Int32, p_lAuthorAreaHeight);
            db.AddInParameter(dbCommand, "p_lOCR_MASK_DOC_AUT_HEIGHT", DbType.Int32, p_lAuthorAreaWidth);
            db.AddInParameter(dbCommand, "p_iOCR_MASK_DOC_AUT_TYPE_ID", DbType.Int32, p_lAuthorOcrType);

            //Chrono Number Informations
            db.AddInParameter(dbCommand, "p_sOCR_MASK_DOC_CHR_ZONE_NAME", DbType.String, p_sChronoNumberAreaName);
            db.AddInParameter(dbCommand, "p_lOCR_MASK_DOC_CHR_X", DbType.Int32, p_lChronoNumberAreaTopLeftXCoord);
            db.AddInParameter(dbCommand, "p_lOCR_MASK_DOC_CHR_Y", DbType.Int32, p_lChronoNumberAreaTopLeftYCoord);
            db.AddInParameter(dbCommand, "p_lOCR_MASK_DOC_CHR_WIDTH", DbType.Int32, p_lChronoNumberAreaHeight);
            db.AddInParameter(dbCommand, "p_lOCR_MASK_DOC_CHR_HEIGHT", DbType.Int32, p_lChronoNumberAreaWidth);
            db.AddInParameter(dbCommand, "p_iOCR_MASK_DOC_CHR_TYPE_ID", DbType.Int32, p_lChronoNumberOcrType);

            db.ExecuteNonQuery(dbCommand);
        }

        /// <summary>
        /// Deletes the mask.
        /// </summary>
        /// <param name="p_lOcrMaskId">p_lOcrMaskId</param>
        /// <returns></returns>
        public static void DeleteMask(long p_lOcrMaskId)
        {
            var db = DbHelper.DataBase;
            var dbCommand = db.GetNewCommand(DbFunction.DeleteMask.szGetDescription(), false);
            db.AddInParameter(dbCommand, "p_lOcrMaskId", DbType.Int32, p_lOcrMaskId);
            db.ExecuteNonQuery(dbCommand);
        }

        /// <summary>
        /// Gets the mask by folder type id.
        /// </summary>
        /// <param name="p_lFolderTypeId">p_lFolderTypeId</param>
        /// <returns></returns>
        public static IDataReader GetMaskByFolderTypeId(long p_lFolderTypeId)
        {
            var db = DbHelper.DataBase;

            var dbCommand = db.GetNewCommand(DbFunction.GetMaskByFolerTypeId.szGetDescription());
            db.AddInParameter(dbCommand, "p_lFolderTypeId", DbType.Int32, p_lFolderTypeId);

            return db.ExecuteReader(dbCommand);
        }

        /// <summary>
        /// Gets the mask by id.
        /// </summary>
        /// <param name="p_lMaskId">p_lMaskId</param>
        /// <returns></returns>
        public static IDataReader GetMaskById(long p_lMaskId)
        {
            var db = DbHelper.DataBase;
            var dbCommand = db.GetNewCommand(DbFunction.GetMaskById.szGetDescription());

            db.AddInParameter(dbCommand, "p_lOcrMaskId", DbType.Int32, p_lMaskId);

            return db.ExecuteReader(dbCommand);
        }

        /// <summary>
        /// Adds the region.
        /// </summary>
        /// <param name="p_lOcrMaskId">p_lOcrMaskId</param>
        /// <param name="p_lIndexId">p_lIndexId</param>
        /// <param name="p_lRegionTopLeftXCoord">p_lRegionTopLeftXCoord</param>
        /// <param name="p_lRegionTopLeftYCoord">p_lRegionTopLeftYCoord</param>
        /// <param name="p_lRegionHeight">p_lRegionHeight</param>
        /// <param name="p_lRegionWidth">p_lRegionWidth</param>
        /// <returns>Identifier of the new region.</returns>
        public static IDataReader AddRegion(long p_lOcrMaskId, long p_lIndexId,
            long p_lRegionTopLeftXCoord, long p_lRegionTopLeftYCoord, long p_lRegionHeight, long p_lRegionWidth, string p_sRegionName, long p_lOcrTypeId)
        {
            var db = DbHelper.DataBase;
            var dbCommand = db.GetNewCommand(DbFunction.AddRegion.szGetDescription());

            db.AddInParameter(dbCommand, "p_lOcrMaskId", DbType.Int32, p_lOcrMaskId);
            db.AddInParameter(dbCommand, "p_lIndexId", DbType.Int32, p_lIndexId);
            db.AddInParameter(dbCommand, "p_lRegionTopLeftXCoord", DbType.Int32, p_lRegionTopLeftXCoord);
            db.AddInParameter(dbCommand, "p_lRegionTopLeftYCoord", DbType.Int32, p_lRegionTopLeftYCoord);
            db.AddInParameter(dbCommand, "p_lRegionHeight", DbType.Int32, p_lRegionHeight);
            db.AddInParameter(dbCommand, "p_lRegionWidth", DbType.Int32, p_lRegionWidth);
            db.AddInParameter(dbCommand, "p_sOcrRegionName", DbType.String, p_sRegionName);
            db.AddInParameter(dbCommand, "p_lOcrTypeId", DbType.Int32, p_lOcrTypeId);

            return db.ExecuteReader(dbCommand);
        }

        /// <summary>
        /// Deletes the region.
        /// </summary>
        /// <param name="p_lOcrRegionId">p_lOcrRegionId</param>
        /// <returns></returns>
        public static void DeleteRegion(long p_lOcrRegionId)
        {
            var db = DbHelper.DataBase;
            var dbCommand = db.GetNewCommand(DbFunction.DeleteRegion.szGetDescription(), false);

            db.AddInParameter(dbCommand, "p_lOcrRegionId", DbType.Int32, p_lOcrRegionId);

            db.ExecuteNonQuery(dbCommand);
        }

        /// <summary>
        /// Gets the region by mask id.
        /// </summary>
        /// <param name="p_lOcrMaskId">p_lOcrMaskId</param>
        /// <returns></returns>
        public static IDataReader GetRegionByMaskId(long p_lOcrMaskId)
        {
            var db = DbHelper.DataBase;
            var dbCommand = db.GetNewCommand(DbFunction.GetRegionByMaskId.szGetDescription());

            db.AddInParameter(dbCommand, "plOcrMaskId", DbType.Int32, p_lOcrMaskId);

            return db.ExecuteReader(dbCommand);
        }

        /// <summary>
        /// Updates the region.
        /// </summary>
        /// <param name="p_lOcrRegionId">p_lOcrRegionId</param>
        /// <param name="p_lRegionTopLeftXCoord">p_lRegionTopLeftXCoord</param>
        /// <param name="p_lRegionTopLeftYCoord">p_lRegionTopLeftYCoord</param>
        /// <param name="p_lRegionHeight">p_lRegionHeight</param>
        /// <param name="p_lRegionWidth">p_lRegionWidth</param>
        /// <returns></returns>
        public static void UpdateRegion(long p_lOcrRegionId, long p_lRegionTopLeftXCoord,
            long p_lRegionTopLeftYCoord, long p_lRegionHeight, long p_lRegionWidth, long p_lOcrTypeId, string p_sOcrRegionName)
        {
            var db = DbHelper.DataBase;
            var dbCommand = db.GetNewCommand(DbFunction.UpdateRegion.szGetDescription(), false);

            db.AddInParameter(dbCommand, "p_lOcrRegionId", DbType.Int32, p_lOcrRegionId);
            db.AddInParameter(dbCommand, "p_lRegionTopLeftXCoord", DbType.Int32, p_lRegionTopLeftXCoord);
            db.AddInParameter(dbCommand, "p_lRegionTopLeftYCoord", DbType.Int32, p_lRegionTopLeftYCoord);
            db.AddInParameter(dbCommand, "p_lRegionHeight", DbType.Int32, p_lRegionHeight);
            db.AddInParameter(dbCommand, "p_lRegionWidth", DbType.Int32, p_lRegionWidth);
            db.AddInParameter(dbCommand, "p_lOcrTypeId", DbType.Int32, p_lOcrTypeId);
            db.AddInParameter(dbCommand, "p_sOcrRegionName", DbType.String, p_sOcrRegionName);

            db.ExecuteNonQuery(dbCommand);
        }
    }
}
